<?php
/**
 * @package sunny-cms
 * @author sonny
 * @email sonny@yuranga.com
 * @version 1.0
 */
class MY_Loader extends CI_Loader {
    public $theme = 'default';
    public $theme_path = '';
    public $layout = 'page';
    public function __construct() {
        parent::__construct();
        // Set the loader to use the default theme path.
        $this->set_theme($this->theme);
    }
    
    public function set_theme($theme, $view_cascade = TRUE) {
        // FCPATH
        $this->theme = $theme;
        $this->theme_path = APPPATH . 'themes/' . $theme . '/';
		$this->_ci_view_paths = array($this->theme_path => $view_cascade) + $this->_ci_view_paths;
        //http://codeigniter.tv/
        //https://tutsplus.com/course/build-a-cms-in-codeigniter/
        //https://aampp.net/about
    }
    
    /**
     * 
     * @param type $layout
     * @param type $data
     */
    public function layout($layout, $data) {
        if (file_exists($this->theme_path . $layout . '.php' )) {
            $this->layout = $layout;
        }
        echo $this->view($this->layout, $data, true);
    }
    
    public function get_view_paths() {
        return $this->_ci_view_paths;
    }   
}